﻿using System;
using System.Linq;
using MyFloridaHouse.libSTO;
using MyFloridaHouse.DataAccess;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Types;

namespace MyFloridaHouse.libServiceBusinessRules
{
    public static class ShapeUogIDs
    {
		/// <summary>
		/// Gets the shape uogIDs as a list of ShapeUogIDDTO objects.
		/// </summary>
		/// <param name="iWktList">The iWKT list.</param>
		/// <param name="iLayerID">The ilayerID.</param>
		/// <param name="iDistrictID">The idistrictID.</param>
		/// <returns>Object: <see cref="ShapeUogidSTO"/></returns>
        public static ShapeUogidSTO GetShapeUogIDs(string iWktList, int iLayerID, int iDistrictID)
        {
            ShapeUogidSTO results = new ShapeUogidSTO();
            try
            {
                SqlChars sc = new SqlChars(iWktList.ToString());
                SqlGeometry newGeom = SqlGeometry.STGeomFromText(sc, 4326);
                if (!newGeom.STIsValid())
                {
                    throw new Exception("Can't evaluate your lasso, Please try again without crossing back into the lasso");
                }

                results.districtID = iDistrictID;

                DAL_CensusData dal = new DAL_CensusData();
                var queryResults = dal.GetShapeUogIDs(iWktList, iLayerID);
                results.uogidList = (from q in queryResults select q).ToList();
                return results;
            }
            catch (Exception ex)
            {
                //todo: Log exception
                results.errorMessage = ex.Message;
                return results;
            }
        }

    }
}
